package com.ruslan.magaz.domain;
// default package
// Generated 28.09.2014 13:25:18 by Hibernate Tools 3.4.0.CR1

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.springframework.format.annotation.DateTimeFormat;

import com.ruslan.magaz.web.validation.Alive;
import com.ruslan.magaz.web.validation.TooYoung;

/**
 * Customer generated by hbm2java
 */
@Entity
@Table(name = "customer", catalog = "eshop")
public class Customer implements java.io.Serializable {

	private int customerId;
	private User user;
	@Size(min=1,max=30,message=	"First Name must be between 1 and 30 characters long.")
	@Pattern(regexp="(?U)^\\w(\\w|[ \\-'])*\\w$",	message="Illegal format")
	private String firstName;
	@Size(min=1,max=30,message=	"Last Name must be between 1 and 30 characters long.")
	@Pattern(regexp="(?U)^\\w(\\w|[ \\-'])*\\w$",	message="Illegal format")
	private String lastName;
	private boolean gender;
//	@DateTimeFormat(pattern = "dd.MM.yy")
//	@DateTimeFormat(pattern="^\\d\\d-\\d\\d-\\d\\d\\d\\d$")
	@Past
	@Alive
	@TooYoung
	private Date birthDate;
	private Integer actualDiscount;
	private Date registrationDate;
	private Set<Order> orders = new HashSet<Order>(0);
	private Set<Address> addresses = new HashSet<Address>(0);
	private int shippingAddressId;

	public Customer() {
	}

	public Customer(int customerId, User user) {
		this.customerId = customerId;
		this.user = user;
	}

	public Customer(int customerId, User user, String firstName,
			String lastName, boolean gender, Date birthDate,
			Integer actualDiscount, Date registrationDate,
			Set<Order> orders, Set<Address> addresses, int shippingAddressId) {
		this.customerId = customerId;
		this.user = user;
		this.firstName = firstName;
		this.lastName = lastName;
		this.gender = gender;
		this.birthDate = birthDate;
		this.actualDiscount = actualDiscount;
		this.registrationDate = registrationDate;
		this.orders = orders;
		this.addresses = addresses;
		this.shippingAddressId = shippingAddressId;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "Customer_id", unique = true, nullable = false)
	public int getCustomerId() {
		return this.customerId;
	}

	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "User_id", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "FirstName", length = 100)
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "LastName", length = 100)
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "Gender", length = 100)
	public boolean getGender() {
		return this.gender;
	}

	public void setGender(boolean gender) {
		this.gender = gender;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "BirthDate", length = 10)
	public Date getBirthDate() {
		return this.birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	@Column(name = "ActualDiscount")
	public Integer getActualDiscount() {
		return this.actualDiscount;
	}

	public void setActualDiscount(Integer actualDiscount) {
		this.actualDiscount = actualDiscount;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "RegistrationDate", length = 19)
	public Date getRegistrationDate() {
		return this.registrationDate;
	}

	public void setRegistrationDate(Date registrationDate) {
		this.registrationDate = registrationDate;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer")
	public Set<Order> getOrders() {
		return this.orders;
	}

	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}


	
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "customer",  cascade=CascadeType.REMOVE)
	public Set<Address> getAddresses() {
		return this.addresses;
	}

	public void setAddresses(Set<Address> addresses) {
		this.addresses = addresses;
	}
	
	@Column(name = "ShippingAddressId")
	public int getShippingAddressId() {
		return this.shippingAddressId;
	}
	
	public void setShippingAddressId(int shippingAddressId) {
		this.shippingAddressId = shippingAddressId;
	}
	
//	public void addAddress(Address address) {
//		addresses.add(address);
//	}
}
